<template>
  <div class="main-content">
    <!-- 列表页 -->
    <div v-if="showFlag">
      <el-form :inline="true" :model="searchForm" class="form-content">
        <el-row :gutter="20" class="slt" :style="{justifyContent:contents.searchBoxPosition=='1'?'flex-start':contents.searchBoxPosition=='2'?'center':'flex-end'}">
                                                    <el-form-item :label="contents.inputTitle == 1 ? '课程名称' : ''">
                  <el-select v-model="searchForm.kechengmingcheng" placeholder="选择课程" clearable>
                    <el-option v-for="item in courseOptions" :key="item" :label="item" :value="item"></el-option>
                  </el-select>
                </el-form-item>
                                                                                                    <el-form-item :label="contents.inputTitle == 1 ? '课题名称' : ''">
                  <el-input v-if="contents.inputIcon == 1 && contents.inputIconPosition == 1" prefix-icon="el-icon-search" v-model="searchForm.ketimingcheng" placeholder="课题名称" clearable></el-input>
                  <el-input v-if="contents.inputIcon == 1 && contents.inputIconPosition == 2" suffix-icon="el-icon-search" v-model="searchForm.ketimingcheng" placeholder="课题名称" clearable></el-input>
                  <el-input v-if="contents.inputIcon == 0" v-model="searchForm.ketimingcheng" placeholder="课题名称" clearable></el-input>
                </el-form-item>
                                                                                                    <el-form-item :label="contents.inputTitle == 1 ? '提交类型' : ''">
                  <el-select v-model="searchForm.zuoyeleixing" placeholder="提交类型" clearable>
                    <el-option label="日志提交" value="日志提交"></el-option>
                    <el-option label="课题提交" value="课题提交"></el-option>
                  </el-select>
                </el-form-item>
                                                                                                    <el-form-item :label="contents.inputTitle == 1 ? '班级' : ''">
                  <el-select v-model="searchForm.banji" placeholder="选择班级" clearable>
                    <el-option v-for="item in classOptions" :key="item" :label="item" :value="item"></el-option>
                  </el-select>
                </el-form-item>
                                                                                                                                                                                                                  <el-form-item :label="contents.inputTitle == 1 ? '教师姓名' : ''">
                  <el-input v-if="contents.inputIcon == 1 && contents.inputIconPosition == 1" prefix-icon="el-icon-search" v-model="searchForm.jiaoshixingming" placeholder="教师姓名" clearable></el-input>
                  <el-input v-if="contents.inputIcon == 1 && contents.inputIconPosition == 2" suffix-icon="el-icon-search" v-model="searchForm.jiaoshixingming" placeholder="教师姓名" clearable></el-input>
                  <el-input v-if="contents.inputIcon == 0" v-model="searchForm.jiaoshixingming" placeholder="教师姓名" clearable></el-input>
                </el-form-item>
                                                                              <el-form-item :label="contents.inputTitle == 1 ? '学号' : ''">
                  <el-input v-if="contents.inputIcon == 1 && contents.inputIconPosition == 1" prefix-icon="el-icon-search" v-model="searchForm.xuehao" placeholder="学号" clearable></el-input>
                  <el-input v-if="contents.inputIcon == 1 && contents.inputIconPosition == 2" suffix-icon="el-icon-search" v-model="searchForm.xuehao" placeholder="学号" clearable></el-input>
                  <el-input v-if="contents.inputIcon == 0" v-model="searchForm.xuehao" placeholder="学号" clearable></el-input>
                </el-form-item>
                                                                    <el-form-item>
            <el-button v-if="contents.searchBtnIcon == 1 && contents.searchBtnIconPosition == 1" icon="el-icon-search" type="success" @click="search()">{{ contents.searchBtnFont == 1?'查询':'' }}</el-button>
            <el-button v-if="contents.searchBtnIcon == 1 && contents.searchBtnIconPosition == 2" type="success" @click="search()">{{ contents.searchBtnFont == 1?'查询':'' }}<i class="el-icon-search el-icon--right"/></el-button>
            <el-button v-if="contents.searchBtnIcon == 0" type="success" @click="search()">{{ contents.searchBtnFont == 1?'查询':'' }}</el-button>
          </el-form-item>
        </el-row>
        <el-row class="ad" :style="{justifyContent:contents.btnAdAllBoxPosition=='1'?'flex-start':contents.btnAdAllBoxPosition=='2'?'center':'flex-end'}">
          <el-form-item>
            <el-button
              v-if="isAuth('zuoyepingfen','新增') && contents.btnAdAllIcon == 1 && contents.btnAdAllIconPosition == 1"
              type="success"
              icon="el-icon-plus"
              @click="addOrUpdateHandler()"
            >{{ contents.btnAdAllFont == 1?'新增':'' }}</el-button>
            <el-button
              v-if="isAuth('zuoyepingfen','新增') && contents.btnAdAllIcon == 1 && contents.btnAdAllIconPosition == 2"
              type="success"
              @click="addOrUpdateHandler()"
            >{{ contents.btnAdAllFont == 1?'新增':'' }}<i class="el-icon-plus el-icon--right" /></el-button>
            <el-button
              v-if="isAuth('zuoyepingfen','新增') && contents.btnAdAllIcon == 0"
              type="success"
              @click="addOrUpdateHandler()"
            >{{ contents.btnAdAllFont == 1?'新增':'' }}</el-button>
            <el-button
              v-if="isAuth('zuoyepingfen','删除') && contents.btnAdAllIcon == 1 && contents.btnAdAllIconPosition == 1 && contents.tableSelection"
              :disabled="dataListSelections.length <= 0"
              type="danger"
              icon="el-icon-delete"
              @click="deleteHandler()"
            >{{ contents.btnAdAllFont == 1?'删除':'' }}</el-button>
            <el-button
              v-if="isAuth('zuoyepingfen','删除') && contents.btnAdAllIcon == 1 && contents.btnAdAllIconPosition == 2 && contents.tableSelection"
              :disabled="dataListSelections.length <= 0"
              type="danger"
              @click="deleteHandler()"
            >{{ contents.btnAdAllFont == 1?'删除':'' }}<i class="el-icon-delete el-icon--right" /></el-button>
            <el-button
              v-if="isAuth('zuoyepingfen','删除') && contents.btnAdAllIcon == 0 && contents.tableSelection"
              :disabled="dataListSelections.length <= 0"
              type="danger"
              @click="deleteHandler()"
            >{{ contents.btnAdAllFont == 1?'删除':'' }}</el-button>

            <!-- 添加统计分析按钮 -->
            <el-button v-if="isAuth('zuoyepingfen','查看')" type="warning" @click="chartDialog()" style="margin-left: 10px;">统计分析</el-button>
            <!-- 添加学生成绩总览按钮 -->
            <el-button v-if="isAuth('zuoyepingfen','查看')" type="success" @click="overviewDialog()" style="margin-left: 10px;">学生成绩总览</el-button>
          </el-form-item>
        </el-row>
      </el-form>
      <div class="table-content">
        <el-table class="tables" :size="contents.tableSize" :show-header="contents.tableShowHeader"
            :header-row-style="headerRowStyle" :header-cell-style="headerCellStyle"
            :border="contents.tableBorder"
            :fit="contents.tableFit"
            :stripe="contents.tableStripe"
            :row-style="rowStyle"
            :cell-style="cellStyle"
            :style="{width: '100%',fontSize:contents.tableContentFontSize,color:contents.tableContentFontColor}"
            v-if="isAuth('zuoyepingfen','查看')"
            :data="dataList"
            v-loading="dataListLoading"
            @selection-change="selectionChangeHandler">
            <el-table-column  v-if="contents.tableSelection"
                type="selection"
                header-align="center"
                align="center"
                width="50">
            </el-table-column>
            <el-table-column label="索引" v-if="contents.tableIndex" type="index" width="50" />
            	                                    <el-table-column  :sortable="contents.tableSortable" :align="contents.tableAlign"
                    prop="kechengmingcheng"
                    header-align="center"
		    label="课程名称">
		     <template slot-scope="scope">
                       {{scope.row.kechengmingcheng}}
                     </template>
                </el-table-column>
                	                	                                    <el-table-column  :sortable="contents.tableSortable" :align="contents.tableAlign"
                    prop="ketimingcheng"
                    header-align="center"
		    label="课题名称">
		     <template slot-scope="scope">
                       {{scope.row.ketimingcheng}}
                     </template>
                </el-table-column>
                	                	                                    <el-table-column  :sortable="contents.tableSortable" :align="contents.tableAlign"
                    prop="zuoyeleixing"
                    header-align="center"
		    label="提交类型">
		     <template slot-scope="scope">
                       <el-tag v-if="scope.row.zuoyeleixing === '课题提交'" type="danger" size="medium">{{ scope.row.zuoyeleixing }}</el-tag>
                       <el-tag v-else type="success" size="medium">{{ scope.row.zuoyeleixing }}</el-tag>
                     </template>
                </el-table-column>
                	                	                                    <el-table-column  :sortable="contents.tableSortable" :align="contents.tableAlign"
                    prop="xueqi"
                    header-align="center"
		    label="学期">
		     <template slot-scope="scope">
                       {{scope.row.xueqi}}
                     </template>
                </el-table-column>
                	                	                                    <el-table-column  :sortable="contents.tableSortable" :align="contents.tableAlign"
                    prop="banji"
                    header-align="center"
		    label="班级">
		     <template slot-scope="scope">
                       {{scope.row.banji}}
                     </template>
                </el-table-column>
                	                	                                      <el-table-column :sortable="contents.tableSortable" :align="contents.tableAlign" prop="zuoye"
                    header-align="center"
                    label="文件">
                    <template slot-scope="scope">
                      <el-button type="text" size="small" @click="download(scope.row.zuoye)">下载</el-button>
                    </template>
                  </el-table-column>
                	                	                                    <el-table-column  :sortable="contents.tableSortable" :align="contents.tableAlign"
                    prop="tijiaoriqi"
                    header-align="center"
		    label="提交日期">
		     <template slot-scope="scope">
                       {{scope.row.tijiaoriqi}}
                     </template>
                </el-table-column>
                	                	                                    <el-table-column  :sortable="contents.tableSortable" :align="contents.tableAlign"
                    prop="pingfen"
                    header-align="center"
		    label="评分">
		     <template slot-scope="scope">
                       {{scope.row.pingfen}}
                     </template>
                </el-table-column>
                	                	                                    <el-table-column  :sortable="contents.tableSortable" :align="contents.tableAlign"
                    prop="pingyu"
                    header-align="center"
		    label="评语">
		     <template slot-scope="scope">
                       {{scope.row.pingyu}}
                     </template>
                </el-table-column>
                	                	                                    <el-table-column  :sortable="contents.tableSortable" :align="contents.tableAlign"
                    prop="dengjiriqi"
                    header-align="center"
		    label="登记日期">
		     <template slot-scope="scope">
                       {{scope.row.dengjiriqi}}
                     </template>
                </el-table-column>
                	                	                                    <el-table-column  :sortable="contents.tableSortable" :align="contents.tableAlign"
                    prop="jiaoshigonghao"
                    header-align="center"
		    label="教师工号">
		     <template slot-scope="scope">
                       {{scope.row.jiaoshigonghao}}
                     </template>
                </el-table-column>
                	                	                                    <el-table-column  :sortable="contents.tableSortable" :align="contents.tableAlign"
                    prop="jiaoshixingming"
                    header-align="center"
		    label="教师姓名">
		     <template slot-scope="scope">
                       {{scope.row.jiaoshixingming}}
                     </template>
                </el-table-column>
                	                	                                    <el-table-column  :sortable="contents.tableSortable" :align="contents.tableAlign"
                    prop="xuehao"
                    header-align="center"
		    label="学号">
		     <template slot-scope="scope">
                       {{scope.row.xuehao}}
                     </template>
                </el-table-column>
                	                	                                    <el-table-column  :sortable="contents.tableSortable" :align="contents.tableAlign"
                    prop="xueshengxingming"
                    header-align="center"
		    label="学生姓名">
		     <template slot-scope="scope">
                       {{scope.row.xueshengxingming}}
                     </template>
                </el-table-column>
                	                                        <el-table-column width="300" :align="contents.tableAlign"
                header-align="center"
                label="操作">
                <template slot-scope="scope">
                                                <el-button v-if="isAuth('zuoyepingfen','修改') && contents.tableBtnIcon == 1 && contents.tableBtnIconPosition == 1" type="primary" icon="el-icon-edit" size="mini" @click="addOrUpdateHandler(scope.row.id)">{{ contents.tableBtnFont == 1?'修改':'' }}</el-button>
                <el-button v-if="isAuth('zuoyepingfen','修改') && contents.tableBtnIcon == 1 && contents.tableBtnIconPosition == 2" type="primary" size="mini" @click="addOrUpdateHandler(scope.row.id)">{{ contents.tableBtnFont == 1?'修改':'' }}<i class="el-icon-edit el-icon--right" /></el-button>
                <el-button v-if="isAuth('zuoyepingfen','修改') && contents.tableBtnIcon == 0" type="primary" size="mini" @click="addOrUpdateHandler(scope.row.id)">{{ contents.tableBtnFont == 1?'修改':'' }}</el-button>




                <el-button v-if="isAuth('zuoyepingfen','删除') && contents.tableBtnIcon == 1 && contents.tableBtnIconPosition == 1" type="danger" icon="el-icon-delete" size="mini" @click="deleteHandler(scope.row.id)">{{ contents.tableBtnFont == 1?'删除':'' }}</el-button>
                <el-button v-if="isAuth('zuoyepingfen','删除') && contents.tableBtnIcon == 1 && contents.tableBtnIconPosition == 2" type="danger" size="mini" @click="deleteHandler(scope.row.id)">{{ contents.tableBtnFont == 1?'删除':'' }}<i class="el-icon-delete el-icon--right" /></el-button>
                <el-button v-if="isAuth('zuoyepingfen','删除') && contents.tableBtnIcon == 0" type="danger" size="mini" @click="deleteHandler(scope.row.id)">{{ contents.tableBtnFont == 1?'删除':'' }}</el-button>
                </template>
            </el-table-column>
        </el-table>
                                                                                                                                                                                                                <el-pagination
          clsss="pages"
          :layout="layouts"
          @size-change="sizeChangeHandle"
          @current-change="currentChangeHandle"
          :current-page="pageIndex"
          :page-sizes="[10, 20, 50, 100]"
          :page-size="Number(contents.pageEachNum)"
          :total="totalPage"
          :small="contents.pageStyle"
          class="pagination-content"
          :background="contents.pageBtnBG"
          :style="{textAlign:contents.pagePosition==1?'left':contents.pagePosition==2?'center':'right'}"
        ></el-pagination>
      </div>
    </div>
    <!-- 添加/修改页面  将父组件的search方法传递给子组件-->
    <add-or-update v-if="addOrUpdateFlag" :parent="this" ref="addOrUpdate"></add-or-update>

    <!-- 添加统计分析对话框 -->
    <el-dialog
      title="成绩统计分析"
      :visible.sync="chartVisiable"
      width="800">
      <div class="analysis-conditions" style="margin-bottom: 20px;">
        <h4>分析条件：</h4>
        <ul style="list-style: none; padding-left: 0;">
          <li v-if="searchForm.zuoyeleixing">提交类型：{{ searchForm.zuoyeleixing }}</li>
          <li v-if="searchForm.banji">班级：{{ searchForm.banji }}</li>
          <li v-if="searchForm.kechengmingcheng">课程：{{ searchForm.kechengmingcheng }}</li>
          <li v-if="!searchForm.banji && !searchForm.kechengmingcheng && !searchForm.zuoyeleixing">全部数据</li>
        </ul>
      </div>
      <div id="chartContainer" style="width:100%;height:600px;">
        <div id="gradeChart" style="width:100%;height:300px;"></div>
        <div id="gradeTable" style="width:100%;height:200px;margin-top:20px;">
          <el-table :data="gradeStats" style="width: 100%">
            <el-table-column prop="range" label="分数区间" width="180"></el-table-column>
            <el-table-column prop="count" label="人数" width="180"></el-table-column>
            <el-table-column prop="percentage" label="占比"></el-table-column>
          </el-table>
        </div>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="chartDialog">返回</el-button>
      </span>
    </el-dialog>
    
    <!-- 添加学生成绩总览对话框 -->
    <el-dialog
      title="学生成绩总览"
      :visible.sync="overviewVisiable"
      width="1000"
      :close-on-click-modal="false"
      custom-class="overview-dialog">
      <div class="analysis-conditions" style="margin-bottom: 20px; background-color: #f5f7fa; padding: 15px; border-radius: 4px;">
        <h4 style="margin: 0 0 10px 0; color: #606266; font-size: 16px;">统计条件：</h4>
        <ul style="list-style: none; padding-left: 0; margin: 0; display: flex; flex-wrap: wrap; gap: 10px;">
          <li v-if="searchForm.kechengmingcheng" class="condition-item">课程名称：{{ searchForm.kechengmingcheng }}</li>
          <li v-if="searchForm.ketimingcheng" class="condition-item">课题名称：{{ searchForm.ketimingcheng }}</li>
          <li v-if="searchForm.zuoyeleixing" class="condition-item">提交类型：{{ searchForm.zuoyeleixing }}</li>
          <li v-if="searchForm.banji" class="condition-item">班级：{{ searchForm.banji }}</li>
          <li v-if="searchForm.jiaoshixingming" class="condition-item">教师姓名：{{ searchForm.jiaoshixingming }}</li>
          <li v-if="searchForm.xuehao" class="condition-item">学号：{{ searchForm.xuehao }}</li>
          <li v-if="!searchForm.kechengmingcheng && !searchForm.ketimingcheng && !searchForm.zuoyeleixing && !searchForm.banji && !searchForm.jiaoshixingming && !searchForm.xuehao" class="condition-item">全部数据</li>
        </ul>
      </div>
      <el-table 
        :data="overviewData" 
        style="width: 100%" 
        border
        :header-cell-style="{
          background: '#f5f7fa',
          color: '#606266',
          fontWeight: 'bold',
          textAlign: 'center'
        }"
        :cell-style="{
          textAlign: 'center'
        }"
        :row-style="{
          height: '50px'
        }">
        <el-table-column prop="xuehao" label="学号" min-width="120"></el-table-column>
        <el-table-column prop="xueshengxingming" label="姓名" min-width="120"></el-table-column>
        <el-table-column prop="kechengmingcheng" label="课程名称" min-width="180"></el-table-column>
        <el-table-column prop="ketimingcheng" label="课题名称" min-width="180"></el-table-column>
        <el-table-column prop="pingfen" label="成绩" min-width="120">
          <template slot-scope="scope">
            <span :style="{
              color: getScoreColor(scope.row.pingfen),
              fontWeight: 'bold'
            }">{{ scope.row.pingfen }}</span>
          </template>
        </el-table-column>
      </el-table>
      <span slot="footer" class="dialog-footer">
        <el-button @click="overviewVisiable = false" type="primary">返回</el-button>
      </span>
    </el-dialog>
    
    
      </div>
</template>
<script>
import AddOrUpdate from "./add-or-update";
export default {
  data() {
    return {
                                                                                                                                                                                                                                                                                    searchForm: {
        kechengmingcheng: '',
        ketimingcheng: '',
        zuoyeleixing: '',
        banji: '',
        jiaoshixingming: '',
        xuehao: '',
        key: ""
      },
      dataList: [],
      pageIndex: 1,
      pageSize: 10,
      totalPage: 0,
      dataListLoading: false,
      dataListSelections: [],
      showFlag: true,
      sfshVisiable: false,
      shForm: {},
      chartVisiable: false,
      overviewVisiable: false,
      overviewData: [],
      addOrUpdateFlag:false,
      gradeStats: [],
      courseOptions: [],
      classOptions: [],
      contents:{"searchBtnFontColor":"rgba(159, 111, 85, 0.88)","pagePosition":"1","inputFontSize":"14px","inputBorderRadius":"20px","tableBtnDelFontColor":"#333","tableBtnIconPosition":"1","searchBtnHeight":"40px","inputIconColor":"#C0C4CC","searchBtnBorderRadius":"20px","tableStripe":false,"btnAdAllWarnFontColor":"#333","tableBtnDelBgColor":"rgba(214, 186, 232, 1)","searchBtnIcon":"1","tableSize":"medium","searchBtnBorderStyle":"solid","tableSelection":true,"searchBtnBorderWidth":"1px","tableContentFontSize":"14px","searchBtnBgColor":"rgba(251, 251, 251, 0.66)","inputTitleSize":"16px","btnAdAllBorderColor":"#DCDFE6","pageJumper":true,"btnAdAllIconPosition":"1","searchBoxPosition":"1","tableBtnDetailFontColor":"#333","tableBtnHeight":"40px","pagePager":true,"searchBtnBorderColor":"#DCDFE6","tableHeaderFontColor":"rgba(159, 111, 85, 0.88)","inputTitle":"1","tableBtnBorderRadius":"20px","btnAdAllFont":"1","btnAdAllDelFontColor":"#333","tableBtnIcon":"1","btnAdAllHeight":"40px","btnAdAllWarnBgColor":"rgba(201, 198, 239, 1)","btnAdAllBorderWidth":"1px","tableStripeFontColor":"#606266","tableBtnBorderStyle":"solid","inputHeight":"40px","btnAdAllBorderRadius":"20px","btnAdAllDelBgColor":"rgba(255, 76, 10, 0.71)","pagePrevNext":true,"btnAdAllAddBgColor":"rgba(242, 225, 132, 1)","searchBtnFont":"1","tableIndex":true,"btnAdAllIcon":"1","tableSortable":true,"pageSizes":true,"tableFit":true,"pageBtnBG":true,"searchBtnFontSize":"14px","tableBtnEditBgColor":"rgba(202, 235, 202, 1)","inputBorderWidth":"1px","inputFontPosition":"2","inputFontColor":"#333","pageEachNum":10,"tableHeaderBgColor":"rgba(234, 220, 220, 0.32)","inputTitleColor":"rgba(159, 111, 85, 0.88)","btnAdAllBoxPosition":"1","tableBtnDetailBgColor":"rgba(173, 241, 242, 1)","inputIcon":"0","searchBtnIconPosition":"1","btnAdAllFontSize":"14px","inputBorderStyle":"solid","inputBgColor":"rgba(242, 229, 229, 0.66)","pageStyle":false,"pageTotal":true,"btnAdAllAddFontColor":"#333","tableBtnFont":"1","tableContentFontColor":"#606266","inputBorderColor":"#DCDFE6","tableShowHeader":true,"tableBtnFontSize":"14px","tableBtnBorderColor":"#DCDFE6","inputIconPosition":"1","tableBorder":true,"btnAdAllBorderStyle":"solid","tableBtnBorderWidth":"1px","tableStripeBgColor":"#F5F7FA","tableBtnEditFontColor":"#333","tableAlign":"center"},
      layouts: '',


    };
  },
  created() {
    this.init();
    this.getDataList();
    this.contentStyleChange()
    this.getClassesAndCourses()
  },
  mounted() {

  },
  filters: {
    htmlfilter: function (val) {
      return val.replace(/<[^>]*>/g).replace(/undefined/g,'');
    }
  },
  components: {
    AddOrUpdate,
      },
  methods: {
    contentStyleChange() {

      this.contentPageStyleChange()
    },
    contentSearchStyleChange() {
      this.$nextTick(()=>{
        document.querySelectorAll('.form-content .slt .el-input__inner').forEach(el=>{
          let textAlign = 'left'
          if(this.contents.inputFontPosition == 2) textAlign = 'center'
          if(this.contents.inputFontPosition == 3) textAlign = 'right'
          el.style.textAlign = textAlign
          el.style.height = this.contents.inputHeight
          el.style.lineHeight = this.contents.inputHeight
          el.style.color = this.contents.inputFontColor
          el.style.fontSize = this.contents.inputFontSize
          el.style.borderWidth = this.contents.inputBorderWidth
          el.style.borderStyle = this.contents.inputBorderStyle
          el.style.borderColor = this.contents.inputBorderColor
          el.style.borderRadius = this.contents.inputBorderRadius
          el.style.backgroundColor = this.contents.inputBgColor
        })
        if(this.contents.inputTitle) {
          document.querySelectorAll('.form-content .slt .el-form-item__label').forEach(el=>{
            el.style.color = this.contents.inputTitleColor
            el.style.fontSize = this.contents.inputTitleSize
            el.style.lineHeight = this.contents.inputHeight
          })
        }
        setTimeout(()=>{
          document.querySelectorAll('.form-content .slt .el-input__prefix').forEach(el=>{
            el.style.color = this.contents.inputIconColor
            el.style.lineHeight = this.contents.inputHeight
          })
          document.querySelectorAll('.form-content .slt .el-input__suffix').forEach(el=>{
            el.style.color = this.contents.inputIconColor
            el.style.lineHeight = this.contents.inputHeight
          })
          document.querySelectorAll('.form-content .slt .el-input__icon').forEach(el=>{
            el.style.lineHeight = this.contents.inputHeight
          })
        },10)

      })
    },
    // 搜索按钮
    contentSearchBtnStyleChange() {
      this.$nextTick(()=>{
        document.querySelectorAll('.form-content .slt .el-button--success').forEach(el=>{
          el.style.height = this.contents.searchBtnHeight
          el.style.color = this.contents.searchBtnFontColor
          el.style.fontSize = this.contents.searchBtnFontSize
          el.style.borderWidth = this.contents.searchBtnBorderWidth
          el.style.borderStyle = this.contents.searchBtnBorderStyle
          el.style.borderColor = this.contents.searchBtnBorderColor
          el.style.borderRadius = this.contents.searchBtnBorderRadius
          el.style.backgroundColor = this.contents.searchBtnBgColor
        })
      })
    },
    // 新增、批量删除
    contentBtnAdAllStyleChange() {
      this.$nextTick(()=>{
        document.querySelectorAll('.form-content .ad .el-button--success').forEach(el=>{
          el.style.height = this.contents.btnAdAllHeight
          el.style.color = this.contents.btnAdAllAddFontColor
          el.style.fontSize = this.contents.btnAdAllFontSize
          el.style.borderWidth = this.contents.btnAdAllBorderWidth
          el.style.borderStyle = this.contents.btnAdAllBorderStyle
          el.style.borderColor = this.contents.btnAdAllBorderColor
          el.style.borderRadius = this.contents.btnAdAllBorderRadius
          el.style.backgroundColor = this.contents.btnAdAllAddBgColor
        })
        document.querySelectorAll('.form-content .ad .el-button--danger').forEach(el=>{
          el.style.height = this.contents.btnAdAllHeight
          el.style.color = this.contents.btnAdAllDelFontColor
          el.style.fontSize = this.contents.btnAdAllFontSize
          el.style.borderWidth = this.contents.btnAdAllBorderWidth
          el.style.borderStyle = this.contents.btnAdAllBorderStyle
          el.style.borderColor = this.contents.btnAdAllBorderColor
          el.style.borderRadius = this.contents.btnAdAllBorderRadius
          el.style.backgroundColor = this.contents.btnAdAllDelBgColor
        })
        document.querySelectorAll('.form-content .ad .el-button--warning').forEach(el=>{
          el.style.height = this.contents.btnAdAllHeight
          el.style.color = this.contents.btnAdAllWarnFontColor
          el.style.fontSize = this.contents.btnAdAllFontSize
          el.style.borderWidth = this.contents.btnAdAllBorderWidth
          el.style.borderStyle = this.contents.btnAdAllBorderStyle
          el.style.borderColor = this.contents.btnAdAllBorderColor
          el.style.borderRadius = this.contents.btnAdAllBorderRadius
          el.style.backgroundColor = this.contents.btnAdAllWarnBgColor
        })
      })
    },
    // 表格
    rowStyle({ row, rowIndex}) {
      if (rowIndex % 2 == 1) {
        if(this.contents.tableStripe) {
          return {color:this.contents.tableStripeFontColor}
        }
      } else {
        return ''
      }
    },
    cellStyle({ row, rowIndex}){
      if (rowIndex % 2 == 1) {
        if(this.contents.tableStripe) {
          return {backgroundColor:this.contents.tableStripeBgColor}
        }
      } else {
        return ''
      }
    },
    headerRowStyle({ row, rowIndex}){
      return {color: this.contents.tableHeaderFontColor}
    },
    headerCellStyle({ row, rowIndex}){
      return {backgroundColor: this.contents.tableHeaderBgColor}
    },
    // 表格按钮
    contentTableBtnStyleChange(){
      // this.$nextTick(()=>{
      //   setTimeout(()=>{
      //     document.querySelectorAll('.table-content .tables .el-table__body .el-button--success').forEach(el=>{
      //       el.style.height = this.contents.tableBtnHeight
      //       el.style.color = this.contents.tableBtnDetailFontColor
      //       el.style.fontSize = this.contents.tableBtnFontSize
      //       el.style.borderWidth = this.contents.tableBtnBorderWidth
      //       el.style.borderStyle = this.contents.tableBtnBorderStyle
      //       el.style.borderColor = this.contents.tableBtnBorderColor
      //       el.style.borderRadius = this.contents.tableBtnBorderRadius
      //       el.style.backgroundColor = this.contents.tableBtnDetailBgColor
      //     })
      //     document.querySelectorAll('.table-content .tables .el-table__body .el-button--primary').forEach(el=>{
      //       el.style.height = this.contents.tableBtnHeight
      //       el.style.color = this.contents.tableBtnEditFontColor
      //       el.style.fontSize = this.contents.tableBtnFontSize
      //       el.style.borderWidth = this.contents.tableBtnBorderWidth
      //       el.style.borderStyle = this.contents.tableBtnBorderStyle
      //       el.style.borderColor = this.contents.tableBtnBorderColor
      //       el.style.borderRadius = this.contents.tableBtnBorderRadius
      //       el.style.backgroundColor = this.contents.tableBtnEditBgColor
      //     })
      //     document.querySelectorAll('.table-content .tables .el-table__body .el-button--danger').forEach(el=>{
      //       el.style.height = this.contents.tableBtnHeight
      //       el.style.color = this.contents.tableBtnDelFontColor
      //       el.style.fontSize = this.contents.tableBtnFontSize
      //       el.style.borderWidth = this.contents.tableBtnBorderWidth
      //       el.style.borderStyle = this.contents.tableBtnBorderStyle
      //       el.style.borderColor = this.contents.tableBtnBorderColor
      //       el.style.borderRadius = this.contents.tableBtnBorderRadius
      //       el.style.backgroundColor = this.contents.tableBtnDelBgColor
      //     })

      //   }, 50)
      // })
    },
    // 分页
    contentPageStyleChange(){
      let arr = []

      if(this.contents.pageTotal) arr.push('total')
      if(this.contents.pageSizes) arr.push('sizes')
      if(this.contents.pagePrevNext){
        arr.push('prev')
        if(this.contents.pagePager) arr.push('pager')
        arr.push('next')
      }
      if(this.contents.pageJumper) arr.push('jumper')
      this.layouts = arr.join()
      this.contents.pageEachNum = 10
    },

                init () {
                                                                                                                                                                                                                                                                                                                                                                                                },
    search() {
      this.pageIndex = 1;
      this.getDataList();
    },
    // 获取数据列表
    getDataList() {
      this.dataListLoading = true;
      let params = {
        page: this.pageIndex,
        limit: this.pageSize,
        sort: 'id',
      }
      if(this.searchForm.kechengmingcheng!='' && this.searchForm.kechengmingcheng!=undefined){
        params['kechengmingcheng'] = this.searchForm.kechengmingcheng;
      }
      if(this.searchForm.ketimingcheng!='' && this.searchForm.ketimingcheng!=undefined){
        params['ketimingcheng'] = this.searchForm.ketimingcheng;
      }
      if(this.searchForm.zuoyeleixing!='' && this.searchForm.zuoyeleixing!=undefined){
        params['zuoyeleixing'] = this.searchForm.zuoyeleixing;
      }
      if(this.searchForm.banji!='' && this.searchForm.banji!=undefined){
        params['banji'] = this.searchForm.banji;
      }
      if(this.searchForm.jiaoshixingming!='' && this.searchForm.jiaoshixingming!=undefined){
        params['jiaoshixingming'] = this.searchForm.jiaoshixingming;
      }
      if(this.searchForm.xuehao!='' && this.searchForm.xuehao!=undefined){
        params['xuehao'] = this.searchForm.xuehao;
      }
      this.$http({
        url: "zuoyepingfen/page",
        method: "get",
        params: params
      }).then(({ data }) => {
        if (data && data.code === 0) {
          this.dataList = data.data.list;
          this.totalPage = data.data.total;
        } else {
          this.dataList = [];
          this.totalPage = 0;
        }
        this.dataListLoading = false;
      });
    },
    // 每页数
    sizeChangeHandle(val) {
      this.pageSize = val;
      this.pageIndex = 1;
      this.getDataList();
    },
    // 当前页
    currentChangeHandle(val) {
      this.pageIndex = val;
      this.getDataList();
    },
    // 多选
    selectionChangeHandler(val) {
      this.dataListSelections = val;
    },
    // 添加/修改
    addOrUpdateHandler(id,type) {
      this.showFlag = false;
      this.addOrUpdateFlag = true;
      this.crossAddOrUpdateFlag = false;
      if(type!='info'){
        type = 'else';
      }
      this.$nextTick(() => {
        this.$refs.addOrUpdate.init(id,type);
      });
    },
    // 查看评论
        // 下载
    download(file){
      window.open(`${file}`)
    },
    // 删除
    deleteHandler(id) {
      var ids = id
        ? [Number(id)]
        : this.dataListSelections.map(item => {
            return Number(item.id);
          });
      this.$confirm(`确定进行[${id ? "删除" : "批量删除"}]操作?`, "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(() => {
        this.$http({
          url: "zuoyepingfen/delete",
          method: "post",
          data: ids
        }).then(({ data }) => {
          if (data && data.code === 0) {
            this.$message({
              message: "操作成功",
              type: "success",
              duration: 1500,
              onClose: () => {
                this.search();
              }
            });
          } else {
            this.$message.error(data.msg);
          }
        });
      });
    },
    // 添加统计分析方法
    chartDialog() {
      if (!this.chartVisiable) {
        this.chartVisiable = true;
        this.$nextTick(() => {
          var gradeChart = this.$echarts.init(document.getElementById("gradeChart"), 'macarons');
          
          // 使用当前的筛选条件获取成绩数据
          let params = {};
          
          // 添加当前的筛选条件
          if (this.searchForm.zuoyeleixing) {
            params.zuoyeleixing = this.searchForm.zuoyeleixing;
          }
          if (this.searchForm.banji) {
            params.banji = this.searchForm.banji;
          }
          if (this.searchForm.kechengmingcheng) {
            params.kechengmingcheng = this.searchForm.kechengmingcheng;
          }
          
          // 获取成绩统计数据
          this.$http({
            url: "zuoyepingfen/page",
            method: "get",
            params: {
              ...params,
              page: 1,
              limit: 1000 // 获取足够多的数据进行统计
            }
          }).then(({data}) => {
            if (data && data.code === 0) {
              let res = data.data.list;
              
              // 处理成绩区间
              let gradeRanges = [
                {min: 0, max: 59, label: '不及格(0-59)'},
                {min: 60, max: 69, label: '及格(60-69)'},
                {min: 70, max: 79, label: '中等(70-79)'},
                {min: 80, max: 89, label: '良好(80-89)'},
                {min: 90, max: 100, label: '优秀(90-100)'}
              ];
              
              // 初始化统计数据
              let stats = gradeRanges.map(range => ({
                range: range.label,
                count: 0,
                percentage: '0%'
              }));
              
              // 统计各分数段人数
              let total = res.length;
              res.forEach(item => {
                let score = parseInt(item.pingfen);
                for (let i = 0; i < gradeRanges.length; i++) {
                  if (score >= gradeRanges[i].min && score <= gradeRanges[i].max) {
                    stats[i].count++;
                    break;
                  }
                }
              });
              
              // 计算百分比
              stats.forEach(item => {
                item.percentage = total > 0 ? ((item.count / total) * 100).toFixed(2) + '%' : '0%';
              });
              
              this.gradeStats = stats;

              // 计算平均分
              let totalScore = res.reduce((sum, item) => sum + parseInt(item.pingfen), 0);
              let averageScore = total > 0 ? (totalScore / total).toFixed(2) : 0;
              
              // 配置饼图
              let option = {
                title: {
                  text: '成绩分布统计',
                  subtext: `总人数: ${total}人, 平均分: ${averageScore}分`,
                  left: 'center'
                },
                tooltip: {
                  trigger: 'item',
                  formatter: '{b} : {c}人 ({d}%)'
                },
                legend: {
                  orient: 'vertical',
                  left: 'left',
                  data: stats.map(item => item.range)
                },
                series: [
                  {
                    type: 'pie',
                    radius: '55%',
                    center: ['50%', '60%'],
                    data: stats.map(item => ({
                      name: item.range,
                      value: item.count
                    })),
                    emphasis: {
                      itemStyle: {
                        shadowBlur: 10,
                        shadowOffsetX: 0,
                        shadowColor: 'rgba(0, 0, 0, 0.5)'
                      }
                    }
                  }
                ]
              };
              
              gradeChart.setOption(option);
              
              // 窗口大小变化时自适应
              window.addEventListener('resize', function() {
                gradeChart.resize();
              });
            }
          });
        });
      } else {
        this.chartVisiable = false;
      }
    },
    // 添加学生成绩总览方法
    overviewDialog() {
      if (!this.overviewVisiable) {
        this.overviewVisiable = true;
        this.$nextTick(() => {
          // 使用当前的筛选条件获取成绩数据
          let params = {};
          
          // 添加当前的筛选条件
          if (this.searchForm.kechengmingcheng) {
            params.kechengmingcheng = this.searchForm.kechengmingcheng;
          }
          if (this.searchForm.ketimingcheng) {
            params.ketimingcheng = this.searchForm.ketimingcheng;
          }
          if (this.searchForm.zuoyeleixing) {
            params.zuoyeleixing = this.searchForm.zuoyeleixing;
          }
          if (this.searchForm.banji) {
            params.banji = this.searchForm.banji;
          }
          if (this.searchForm.jiaoshixingming) {
            params.jiaoshixingming = this.searchForm.jiaoshixingming;
          }
          if (this.searchForm.xuehao) {
            params.xuehao = this.searchForm.xuehao;
          }
          
          // 获取成绩数据
          this.$http({
            url: "zuoyepingfen/page",
            method: "get",
            params: {
              ...params,
              page: 1,
              limit: 1000 // 获取足够多的数据进行展示
            }
          }).then(({ data }) => {
            if (data && data.code === 0) {
              this.overviewData = data.data.list;
            } else {
              this.overviewData = [];
              this.$message.error(data.msg);
            }
          });
        });
      } else {
        this.overviewVisiable = false;
      }
    },
    async getClassesAndCourses() {
      try {
        // 获取班级列表
        const classResponse = await this.$http({
          url: "banji/page",
          method: "get",
          params: {
            page: 1,
            limit: 100,
            sort: 'id'
          }
        });
        if (classResponse.data.code === 0) {
          // 从返回的数据中提取班级名称
          this.classOptions = classResponse.data.data.list.map(item => item.banji);
        }
        
        // 获取课程列表
        const courseResponse = await this.$http({
          url: "kechengxinxi/page",
          method: "get",
          params: {
            page: 1,
            limit: 100,
            sort: 'id'
          }
        });
        if (courseResponse.data.code === 0) {
          // 从返回的数据中提取课程名称
          this.courseOptions = courseResponse.data.data.list.map(item => item.kechengmingcheng);
        }
      } catch (error) {
        console.error('获取班级和课程列表失败:', error);
      }
    },
    // 添加获取成绩颜色的方法
    getScoreColor(score) {
      score = parseInt(score);
      if (score >= 90) return '#67C23A'; // 优秀 - 绿色
      if (score >= 80) return '#409EFF'; // 良好 - 蓝色
      if (score >= 70) return '#E6A23C'; // 中等 - 橙色
      if (score >= 60) return '#909399'; // 及格 - 灰色
      return '#F56C6C'; // 不及格 - 红色
    },
  }

};
</script>
<style lang="scss" scoped>
  .slt {
    margin: 0 !important;
    display: flex;
  }

  .ad {
    margin: 0 !important;
    display: flex;
  }

  .pages {
    & /deep/ el-pagination__sizes{
      & /deep/ el-input__inner {
        height: 22px;
        line-height: 22px;
      }
    }
  }
  

  .el-button+.el-button {
    margin:0;
  } 

  .tables {


    & /deep/ .el-button {
      margin: 4px;
    }
  }

  // 添加新的样式
  .overview-dialog {
    .condition-item {
      background-color: #fff;
      padding: 6px 12px;
      border-radius: 4px;
      border: 1px solid #dcdfe6;
      font-size: 14px;
      color: #606266;
    }
  }

  /deep/ .el-dialog__header {
    padding: 20px;
    border-bottom: 1px solid #dcdfe6;
  }

  /deep/ .el-dialog__body {
    padding: 20px;
  }

  /deep/ .el-dialog__footer {
    padding: 20px;
    border-top: 1px solid #dcdfe6;
  }
</style>
